package com.mini.controller;


import cn.hutool.core.lang.Assert;
import com.mini.conditon.ChanceCommentCondition;
import com.mini.config.CheckLogin;
import com.mini.model.BusinessChanceCommentRecord;
import com.mini.model.BusinessChanceUserProfile;
import com.mini.model.BusinessUserProfileDic;
import com.mini.service.ChanceCommentService;
import com.mini.service.ChanceUserProfileService;
import com.mini.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/tradition/chance")
@Slf4j
@Api(tags = "传统机会相关-备注和画像")
public class BusinessTraditionChanceExtraController extends BaseController {

    @Autowired
    private ChanceCommentService chanceCommentService;
    @Autowired
    private ChanceUserProfileService chanceUserProfileService;



    @CheckLogin
    @ApiOperation(value = "机会备注-最新的一条备注", notes = "机会备注-最新的一条备注")
    @GetMapping("/comment/lasted")
    public BusinessResult<BusinessChanceCommentRecord> commentLastedRecord(@ApiParam(value = "token", required = true) @RequestHeader String Authorization,
                                                                     @ApiParam(value = "机会ID",required = true) @RequestParam Long chanceId){


        return BusinessResult.createSuccessInstance(chanceCommentService.findLastedRecord(chanceId));
    }



    @CheckLogin
    @ApiOperation(value = "机会备注-保存", notes = "机会备注-保存")
    @PostMapping("/comment/add")
    public BusinessResult<BusinessChanceCommentRecord> commentAdd(@ApiParam(value = "token", required = true) @RequestHeader String Authorization,
                                                           @RequestBody ChanceCommentAddVO param){

        UserVO loginUser = this.getLoginUser(Authorization);

        return BusinessResult.createSuccessInstance(chanceCommentService.insert(param.getChanceId(), param.getComment(), loginUser));

    }


    @CheckLogin
    @ApiOperation(value = "机会备注-分页查询", notes = "机会备注-分页查询")
    @PostMapping("/comment/page")
    public BusinessResult<PageResultVO<BusinessChanceCommentRecord>> commentPage(@ApiParam(value = "token", required = true) @RequestHeader String Authorization,
                                            @RequestBody ChanceCommentCondition param){

        return BusinessResult.createSuccessInstance(this.chanceCommentService.page(param));

    }




    @ApiOperation(value = "用户画像-字典表", notes = "机会用户画像-字典表")
    @GetMapping("/profile/dic")
    public BusinessResult<Map<String, List<BusinessUserProfileDic>>> userProfileDicMap(){


        return BusinessResult.createSuccessInstance(chanceUserProfileService.dicShowMap());
    }


    @CheckLogin
    @ApiOperation(value = "用户画像-用户查询", notes = "机会用户画像-字典表")
    @GetMapping("/profile/get")
    public BusinessResult<Map<String, String>> userProfileGet(@ApiParam(value = "token", required = true) @RequestHeader String Authorization,
                                                              @ApiParam(value = "机会ID") @RequestParam Long chanceId){


        return BusinessResult.createSuccessInstance(chanceUserProfileService.getUserProfile(chanceId));
    }


    @CheckLogin
    @ApiOperation(value = "用户画像-保存", notes = "用户画像-保存")
    @PostMapping("/profile/add")
    public BusinessResult<BusinessChanceUserProfile> userProfileAdd(@ApiParam(value = "token", required = true) @RequestHeader String Authorization,
                                                                @RequestBody ChanceUserProfileAddVO param){

        UserVO loginUser = this.getLoginUser(Authorization);

        return BusinessResult.createSuccessInstance(chanceUserProfileService.save(param, loginUser));

    }


}
